package com.example.teamtribe.main.mine.setting.email;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.example.teamtribe.common.Back;
import com.example.teamtribe.utils.Utility;

public class EmailPresenter implements EmailContract.Presenter {

    private EmailContract.View view;
    private EmailModel model;

    public EmailPresenter(EmailContract.View view) {
        this.view = view;
        model = new EmailModel();
    }

    @Override
    public void sendEmail(String email) {
        if (TextUtils.isEmpty(email)) {
            view.showToast("请输入邮箱地址");
            return;
        }
        if (!email.contains("@")) {
            view.showToast("邮箱地址不合法");
            return;
        }

        view.showProgress();
        model.sendEmail(Utility.getToken(), email, new Back() {
            @Override
            public void success(@Nullable Bundle bundle) {
                view.hideProgress();
                view.setView(bundle.getString("meg"));
            }

            @Override
            public void failure(String meg) {
                view.hideProgress();
                view.showToast(meg);
            }
        });
    }
}
